﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using EasyClassServer.Application;

namespace EasyClassServer.Net
{
    /// <summary>
    /// Http参数
    /// </summary>
    class HttpArgs
    {
        protected Dictionary<string, string> getArgs;
        protected JObject postArgs;
        /// <summary>
        /// 创建HttpArgs消息对象
        /// </summary>
        /// <param name="get_args"></param>
        /// <param name="response"></param>
        public HttpArgs(Dictionary<string,string> get_args, JObject post_args)
        {
            getArgs = get_args;
            postArgs = post_args;
        }
        /// <summary>
        /// 获取指定Get参数的值
        /// </summary>
        /// <param name="key">参数的键</param>
        /// <returns></returns>
        public string GetArgValue(string key)
        {
            if(getArgs.ContainsKey(key))
            {
                return getArgs[key];
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 获取Post参数
        /// </summary>
        /// <returns></returns>
        public JObject GetPostValue()
        {
            if (postArgs == null) return new JObject();
            return postArgs;
        }
    }

    /// <summary>
    /// Http响应参数
    /// </summary>
    class HttpResponseArgs
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public HttpCode Code { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 接口返回数据
        /// </summary>
        public object Data { get; set; }
        /// <summary>
        /// 获取参数对象对应的json字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            JObject jo = JObject.FromObject(this);
            return jo.ToString(Newtonsoft.Json.Formatting.Indented);
        }
    }

    enum HttpCode
    {
        Sucsess = 200,
        Accept = 203,
        Error = 400,
        NotFound = 404
    }
}
